-
Couldn't load subscription status.
- Fork 77
Collocated Cokriging #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Collocated Cokriging #394
Conversation
- Implement Simple Collocated Cokriging (SCCK) extending Krige class - Implement Intrinsic Collocated Cokriging (ICCK) with flexible secondary models - Add comprehensive test suite with 14 test cases covering: - Matrix construction and dimensions - Cross-correlation validation - RHS vector structure - Integration with drift functions - Edge cases (zero/perfect correlation) - Follow gstools patterns: property validation, error handling, documentation - Matrix structure: (n+1) x (n+1) for n conditioning points + 1 secondary variable - Uses Markov model assumption: C_zy(h) = ρ * √(C_zz(h) * C_yy(h)) - All tests passing with proper position handling via pre_pos method
- Clean minimal implementation extending Krige base class - Follows existing gstools design patterns exactly - Only adds cross_corr parameter and secondary_data requirement - Uses (n+1)×(n+1) matrix system solved per estimation point - Full API compatibility: return_var, chunk_size, only_mean, etc. - Proper integration with gstools post-processing and chunking - Zero cross-correlation equals Simple Kriging (verified) - Located in separate cokriging module as requested
Feature/collocated cokriging
- Create CollocatedCokriging base class following kriging module pattern - Refactor SCCK and ICCK as thin wrappers (algorithm='MM1' vs 'intrinsic') - Eliminate ~400 lines of duplicated code - Maintain full backward compatibility - All tests passing (14/14) - Cleaner architecture for future extensibility
|
This is great! I love it. I wanted this for a long time but never found the time to work on it. I have some general questions/remarks:
import gstools as gs
correlo_model = gs.MarkovModel1(
model=gs.Gaussian(dim=1, var=0.5, len_scale=2),
cross_corr=0.8,
secondary_var=1.5,
)
scck = gs.SimpleCollocated(
correlo_model, cond_pos, cond_val,
mean=1.0, secondary_mean=0.5
)Maybe the means could be combined in a list then, or we could also move them into the MarkovModel1 (not sure what makes more sense here), or keep them as is.
|
|
1: I'm not sure if this will work very well with the approach I chose. As you maybe have seen, after some linear algebra reformulations of the problem, SCCK and ICCK can be shown as an extension to simple Kriging, making it not necessary to construct new matrices, that would need to be solved for every estimation point in collocated cokriging. That is also where the normalizer goes currently., it applies in the way it would apply for Simple Kriging. |
|
Hi, I also really like your work, thanks a lot! I suggest that we have a chat about @MuellerSeb's suggestions. The Correlogram base class he is talking about would ensure that we can later add more cokriging methods without breaking the interface. The source checks fail. You have to run a linter on your code, see the instructions at the end of this file. I also think that cokriging is missing after line 148 of Depending on the time you still have for this work, I think an example with 2d data would be really valuable, as I guess most applications will be 2d and many of our users like to have very specific examples. |
|
Hi, |
This commit introduces a new Correlogram base class architecture that
makes collocated cokriging future-proof and extensible for different
cross-covariance models (MM1, MM2, etc.).
**New Features:**
- Added Correlogram abstract base class defining the interface for
cross-covariance models
- Implemented MarkovModel1 as the first concrete correlogram,
encapsulating Markov Model I assumptions
- Correlogram objects now hold all cross-covariance parameters:
primary_model, cross_corr, secondary_var, primary_mean, secondary_mean
**API Changes:**
New (recommended) API:
correlogram = gs.MarkovModel1(
primary_model=model,
cross_corr=0.8,
secondary_var=1.5,
primary_mean=1.0,
secondary_mean=0.5
)
scck = gs.SimpleCollocated(correlogram, cond_pos, cond_val)
Backward compatibility via from_parameters() classmethod (deprecated):
scck = gs.SimpleCollocated.from_parameters(
model, cond_pos, cond_val,
cross_corr=0.8, secondary_var=1.5,
mean=1.0, secondary_mean=0.5
)
**Refactored Classes:**
- CollocatedCokriging: Now accepts correlogram object instead of
individual parameters (cross_corr, secondary_var, etc.)
- SimpleCollocated: Updated to use new API with backward compatibility
- IntrinsicCollocated: Updated to use new API with backward compatibility
- Both classes delegate covariance computation to correlogram
**Benefits:**
- Separation of concerns: Cross-covariance modeling separated from
kriging algorithm
- Extensible: Easy to add MM2, Linear Model of Coregionalization, etc.
- Self-documenting: Explicit about which cross-covariance model is used
- Maintainable: Correlogram classes can be tested independently
- Future-proof: Ready for additional correlogram models
**Testing:**
- Added comprehensive test suite (test_correlogram.py)
- All tests pass with numerical equivalence between old and new API
- Updated examples to demonstrate new API
**Documentation:**
- Updated examples/05_kriging/10_simple_collocated_cokriging.py
- Updated examples/05_kriging/11_intrinsic_collocated_cokriging.py
- Added MarkovModel1 to top-level exports
- Comprehensive docstrings with usage examples
**Future Work:**
- Placeholder for MarkovModel2 implementation
- Potential for other correlogram models (intrinsic correlation, etc.)
Closes: #correlogram-architecture
- Explains new Correlogram base class design - Provides usage examples for MarkovModel1 - Shows how to implement MarkovModel2 (future) - Includes migration guide from old to new API - Documents testing and file structure
|
I think there are no import problems, the linter is just too stupid. from gstools import ( # noqa: I001put |
|
I tried to trace the circular import error and it occurs because krige needs field, it then initializes field with the submodule cond_srf and this needs again krige. I still don't understand why this doesn't happened before. |
Feature/correlogram architecture
…ecture Revert "Feature/correlogram architecture"
This PR adds collocated cokriging methods to GSTools for multivariate geostatistical estimation, allowing users to improve sparse primary variable estimates by leveraging densely-sampled secondary variable data.
Collocated Cokriging Features
Krigebase class for full API compatibilityC_YZ(h) = ρ_YZ(0)·√(C_Z(h)·C_Y(h))gstools.cokrigingsubmodule or top-level:from gstools import SimpleCollocated, IntrinsicCollocatedreturn_var=Truecross_corr ∈ [-1, 1],secondary_var > 0ρ=0recovers Simple Kriging,ρ=±1gives zero ICCK varianceSimple Collocated Cokriging
Uses only collocated secondary data at the estimation point:
Intrinsic Collocated Cokriging
Uses collocated secondary data plus secondary values at all primary locations for more stable variance:
Implementation Details
gstools.cokrigingsubmodule with base class and methodsCollocatedCokrigingbase class handles MM1 formulation and variance computationSimpleCollocatedimplements SCCK estimator:Z*_SCCK = Z*_SK·(1-k·λ_Y0) + λ_Y0·(Y(u0)-m_Y) + k·λ_Y0·m_ZIntrinsicCollocatedimplements ICCK estimator using secondary weightssecondary_dataparameter on callC_YZ(0) = ρ_YZ(0)·√(C_Z(0)·C_Y(0))Krigefunctionality: grids, models, dimensions, anisotropy, drift, normalizersTests
11 tests in
test_cokriging.pytesting only cokriging logic:All tests passing with no warnings.
Examples
Two minimal examples following GSTools conventions (76 & 78 lines):
10_simple_collocated_cokriging.py- SCCK demonstration11_intrinsic_collocated_cokriging.py- ICCK demonstrationReferences